// pages/package/akIsTool/index.js
import isTool from '../../../utils/AKIsTool'


Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputContent: {
      value: "ABC",
      number: "123456",
      email: "qq@qq.com",
      phone: "13456789111",
      price: "19.9",
    },
    inputList: [{
        title: "校验是否有值",
        key: "value"
      },
      {
        title: "校验数字",
        key: "number"
      },
      {
        title: "邮箱",
        key: "email"
      },
      {
        title: "电话",
        key: "phone"
      },
      {
        title: "价格(小数后两位)",
        key: "price"
      },
    ],
    code: `<div spellcheck="false" autocorrect="off" autocapitalize="off" translate="no" contenteditable="true" style="tab-size: 2;" class="cm-content" role="textbox" aria-multiline="true" data-language="javascript" aria-autocomplete="list"><div class="cm-line"><span class="ep">if</span> (<span class="eq">isTool</span></div><div class="cm-line">  <span class="ev">.</span><span class="eq">isHaveValue</span>(<span class="eq">value</span><span class="et">,</span> <span class="e13">"value不能为空"</span>)</div><div class="cm-line">  <span class="ev">.</span><span class="eq">isNumber</span>(<span class="eq">number</span><span class="et">,</span> <span class="e13">"number不能为空"</span><span class="et">,</span> <span class="e13">"number不是数字类型"</span>)</div><div class="cm-line">  <span class="ev">.</span><span class="eq">isEmail</span>(<span class="eq">email</span><span class="et">,</span> <span class="e13">"email不能为空"</span><span class="et">,</span> <span class="e13">"email不是邮箱格式"</span>)</div><div class="cm-activeLine cm-line">  <span class="ev">.</span><span class="eq">isPhone</span><span class="cm-matchingBracket">(</span><span class="eq">phone</span><span class="et">,</span> <span class="e13">"phone不能为空"</span><span class="et">,</span> <span class="e13">"phone不是正确电话格式"</span><span class="cm-matchingBracket">)</span></div><div class="cm-line">  <span class="ev">.</span><span class="eq">isPrice</span>(<span class="eq">price</span><span class="et">,</span> <span class="e13">"price不能为空"</span><span class="et">,</span> <span class="e13">"price不是正确价格格式"</span>)</div><div class="cm-line">  <span class="ev">.</span><span class="eq">isResult</span> <span class="ev">==</span> <span class="e12">false</span>) {</div><div class="cm-line">  <span class="ep">return</span></div><div class="cm-line">}</div><div class="cm-line"><br></div><div class="cm-line"><span class="eq">wx</span><span class="ev">.</span><span class="eq">showToast</span>({</div><div class="cm-line">  <span class="eq">title</span>: <span class="e13">'全部通过'</span><span class="et">,</span></div><div class="cm-line">})</div></div>`
  },
  inputData(e) {
    // console.log("输入",e)
    const key = e.currentTarget.dataset.key
    const inputContent = this.data.inputContent
    inputContent[key] = e.detail.value
    this.setData({
      inputContent
    })
  },
  // 点击:查询
  clickCheck() {
    console.log("点击")
    const {
      email,
      number,
      phone,
      price,
      value,
    } = this.data.inputContent
    if (isTool
      .isHaveValue(value, "value不能为空")
      .isNumber(number, "number不能为空", "number不是数字类型")
      .isEmail(email, "email不能为空", "email不是邮箱格式")
      .isPhone(phone, "phone不能为空", "phone不是正确电话格式")
      .isPrice(price, "price不能为空", "price不是正确价格格式")
      .isResult == false) {
        // wx.showToast({
        //   title: '不全部通过',
        // })
      return
    }

    wx.showToast({
      title: '全部通过',
    })
  },
})